<!DOCTYPE html>
<html>
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>传智健康</title>
    <meta name="description" content="传智健康">
    <meta name="keywords" content="传智健康">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../plugins/elementui/index.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/style.css">
    <!-- 引入组件库 -->
    <script type="text/javascript" src="../js/jquery.min.js"></script>
    <script src="../js/vue.js"></script>
    <script src="../plugins/elementui/index.js"></script>
    <script src="../js/axios-0.18.0.js"></script>
    <style>
        .datatable {
            position: relative;
            box-sizing: border-box;
            -webkit-box-flex: 1;
            width: 100%;
            max-width: 100%;
            font-size: 14px;
            color: rgb(96, 98, 102);
            overflow: hidden;
            flex: 1 1 0%;
        }

        .datatable td, .datatable th {
            padding: 12px 0;
            min-width: 0;
            -webkit-box-sizing: border-box;
            box-sizing: border-box;
            text-overflow: ellipsis;
            vertical-align: middle;
            position: relative;
            text-align: left;
        }
    </style>
</head>
<body class="hold-transition">
<div id="app">
    <div class="content-header">
        <h1>会员管理/<small>体检报告</small></h1>
        <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>会员管理</el-breadcrumb-item>
            <el-breadcrumb-item>体检报告</el-breadcrumb-item>
        </el-breadcrumb>
    </div>
    <div class="app-container">
        <div class="box">
            <div class="filter-container">
                <el-input placeholder="档案号" v-model="pagination.queryString" style="width: 200px;"
                          class="filter-item"></el-input>
                <el-button type="primary" icon="el-icon-search" class="dalfBut" @click="findPage()">查询</el-button>
                <el-button type="primary" icon="el-icon-circle-plus" class="butT" @click="handleCreate()">新建</el-button>
            </div>
            <el-table size="medium" current-row-key="id" :data="dataList" stripe highlight-current-row>
                <el-table-column type="index" align="center" label="序号"></el-table-column>
                <el-table-column prop="PETime" label="体检时间" align="center"></el-table-column>
                <el-table-column prop="fileNumber" label="档案号" align="center"></el-table-column>
                <el-table-column prop="name" label="姓名" align="center"></el-table-column>
                <el-table-column label="操作" align="center">
                    <template slot-scope="scope">
                        <el-button size="mini" type="danger" @click="handleDelete(scope.row)">删除</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination-container">
                <el-pagination
                        class="pagiantion"
                        @current-change="handleCurrentChange"
                        :current-page="pagination.currentPage"
                        :page-size="pagination.pageSize"
                        layout="total, prev, pager, next, jumper"
                        :total="pagination.total">
                </el-pagination>
            </div>
            <!-- 新增标签弹层 -->
            <div class="add-form">
                <el-dialog title="新增报告" :visible.sync="dialogFormVisible" width="500px">
                    <el-form ref="dataAddForm" :model="formData" :rules="rules" label-position="right"
                             label-width="100px">
                        <el-row>
                            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;档案号&nbsp;:&nbsp;
                            <el-select v-model="members.fileNumber" placeholder="请选择" align="center">
                                <el-option
                                        v-for="item in members"
                                        :key="item.fileNumber"
                                        :label="item.fileNumber"
                                        :value="item.fileNumber">
                                    <span style="float: left">{{ item.name }}</span>
                                    <span style="float: right; color: #8492a6; font-size: 13px">档案号&nbsp;:&nbsp;{{ item.fileNumber }}</span>
                                </el-option>
                            </el-select>
                        </el-row>
                        <el-col :span="9">
                            <el-form-item>
                            </el-form-item>
                        </el-col>
                        <el-row>
                        </el-row>
                        <el-row>
                            <el-col :span="18">
                                <el-form-item label="体检时间 : " prop="PETime">
                                    <el-input v-model.trim="formData.PETime"/>
                                </el-form-item>
                            </el-col>
                        </el-row>

                        <el-row>
                            <el-col :span="15">
                                <el-form-item label="数据文件 : " prop="file">
                                    <el-upload
                                            class="upload-demo"
                                            name="fileName"
                                            action="/report/fileUpload.do"
                                            multiple
                                            :limit="3"
                                            :file-list="fileList"
                                            :auto-upload=true>
                                        <el-button size="small" type="primary">点击上传</el-button>
                                    </el-upload>
                                </el-form-item>
                            </el-col>
                        </el-row>
                    </el-form>
                    <div slot="footer" class="dialog-footer">
                        <el-button @click="dialogFormVisible = false">取消</el-button>
                        <el-button type="primary" @click="handleAdd()">确定</el-button>
                    </div>
                </el-dialog>            </div>
        </div>
    </div>
</div>
</body>
<script>
    var vue = new Vue({
        el: '#app',
        data: {
            activeName: 'first',//添加/编辑窗口Tab标签名称
            pagination: {//分页相关属性
                currentPage: 1,
                pageSize: 10,
                total: 100,
                queryString: null,
            },
            // auto-upload:false,
            members: [],//会员下拉列表
            dataList: [],//列表数据
            formData: {},//表单数据
            tableData: [],//新增和编辑表单中对应的检查项列表数据
            dialogFormVisible: false,//控制添加窗口显示/隐藏
            dialogFormVisible4Edit: false,//控制编辑窗口显示/隐藏
            rules: {//校验规则
                fileName: [{required: true, message: '项目编码为必填项', trigger: 'blur'}],
                name: [{required: true, message: '名字为必填项', trigger: 'blur'}],
                idCard: [{required: true, message: '身份证号为必填项', trigger: 'blur'}],
                password: [{required: true, message: '登录密码为必填项', trigger: 'blur'}],
                phoNumber: [{required: true, message: '手机号为必填项', trigger: 'blur'}],
                sex: [{required: true, message: '性别为必填项', trigger: 'blur'}],
                regTime: [{required: true, message: '注册时间为必填项', trigger: 'blur'}],
                marStatus: [{required: true, message: '婚姻状态为必填项', trigger: 'blur'}],
                heaManager: [{required: true, message: '健康管理师为必填项', trigger: 'blur'}],
                fileStatus: [{required: true, message: '档案状态为必填项', trigger: 'blur'}]
            }
        },
        //钩子函数，VUE对象初始化完成后自动执行
        created() {
            this.findPage();
        },
        methods: {
            //编辑弹出框-确认按钮
            handleEdit() {
                console.log(this.formData);
                //1.进行表单校验
                this.$refs['dataEditForm'].validate((valid) => {
                    if (valid) {
                        alert("表单校验通过");
                        //表单校验通过
                        //发送ajax请求,将录入的数据（会员档案信息）提交到后台进行处理
                        axios.post("/report/update.do?fileNumber=" + this.members.fileNumber).then((res) => {
                            if (res.data.flag) {
                                alert("执行成功");
                                //执行成功
                                //弹出成功提示信息
                                this.$message({
                                    message: res.data.message,
                                    type: 'success'
                                });
                            } else {
                                alert("执行失败");
                                //执行失败
                                this.$message.error(res.data.message);
                            }
                        }).finally(() => {
                            //关闭编辑窗口
                            this.dialogFormVisible4Edit = false;
                            //不管成功还是失败,都带调用分页查询方法
                            this.findPage();
                        });
                    } else {
                        alert("表单校验不通过");
                        //表单校验不通过
                        this.$message.error("表单数据校验失败!");
                        return false;
                    }
                });
            },
            //添加弹出框-确认按钮
            handleAdd() {
                //发送ajax请求,将表单数据提交到后台进行处理
                axios.post("/report/add/" + this.members.fileNumber + ".do").then((res) => {
                    if (res.data.flag) {
                        //操作成功
                        this.$message({
                            type: 'success',
                            message: res.data.message
                        });
                    } else {
                        //操作失败
                        this.$message.error(res.data.message);
                    }
                }).finally(() => {
                    //关闭文件自动上传
                    this.auto = false;
                    //清空数据
                    this.resetForm();
                    //关闭表单
                    this.dialogFormVisible = false;
                    //重新进行分页查询
                    this.findPage();
                });
            },
            //分页查询
            findPage() {
                //发送ajax请求,提交分页相关请求参数(页码,每页显示记录数,条件)
                //封装分页参数
                var param = {
                    currentPage: this.pagination.currentPage,//页码
                    pageSize: this.pagination.pageSize,//每页显示的记录数
                    queryString: this.pagination.queryString//查询条件
                };
                //请求后台
                axios.post("/report/findPage.do", param).then((res) => {
                    //位VUE对象的模型数据赋值,基于双向数据绑定展示到页面
                    this.pagination.total = res.data.total;//总数据量
                    this.dataList = res.data.rows;//当前页展示的数据集合
                }).finally(() => {
                    this.pagination.queryString = null;
                });
            },
            // 重置表单
            resetForm() {
                this.formData = {};
            },
            // 弹出添加窗口
            handleCreate() {
                //弹出表单
                this.dialogFormVisible = true;
                //清空表单信息
                this.resetForm();
                //会员信息数据回显
                axios.get("/member/findMember.do").then((res) => {
                    if (res.data.flag) {
                        //查询成功,进行基于VUE的数据绑定实现
                        this.members = res.data.data;
                    } else {
                        //查询失败,弹出提示
                        this.$message.error(res.data.message);
                    }
                });
            },
            // 文件上传
            handleUpload(row) {
                //弹出编辑窗口
                this.dialogFormVisible4Edit = true;
                //设置基本信息表单首先显示
                this.activeName = 'first';
                //回显数据
                // 发送ajax请求,根据id查询出当前检查组数据
                // axios.get("/member/findById.do?id=" + row.id).then((res) => {
                axios.get("/member/findById/" + row.id + ".do").then((res) => {
                    if (res.data.flag) {
                        //弹出编辑窗口
                        this.dialogFormVisible4Edit = true;
                        //查询成功,进行基于VUE的数据绑定实现
                        this.formData = res.data.data;
                    } else {
                        //查询失败,弹出提示
                        this.$message.error(res.data.message);
                    }
                });
            },
            // 弹出编辑窗口
            handleEdit(row) {
                //弹出编辑窗口
                this.dialogFormVisible4Edit = true;
                //设置基本信息表单首先显示
                this.activeName = 'first';
                //回显数据
                // 发送ajax请求,根据id查询出当前检查组数据
                // axios.get("/member/findById.do?id=" + row.id).then((res) => {
                axios.get("/member/findById/" + row.id + ".do").then((res) => {
                    if (res.data.flag) {
                        //弹出编辑窗口
                        this.dialogFormVisible4Edit = true;
                        //查询成功,进行基于VUE的数据绑定实现
                        this.formData = res.data.data;
                    } else {
                        //查询失败,弹出提示
                        this.$message.error(res.data.message);
                    }
                });
            },
            //切换页码
            handleCurrentChange(currentPage) {
                this.pagination.currentPage = currentPage;
                this.findPage();
            },
            // 删除
            handleDelete(row) {
                this.$confirm('此操作将删除该条数据, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    axios.get("/report/delete/" + row.id + ".do").then((res) => {
                        if (res.data.flag) {
                            this.$message.success(res.data.message);
                        } else {
                            this.$message.error(res.data.message);
                            return false;
                        }
                    }).finally(() => {
                            this.findPage();
                        }
                    );
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '操作已取消'
                    });
                });
            }
        }
    })
</script>
</html>
